package com.wanmait.recycle.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;
import com.wanmait.recycle.pojo.Data;
import com.wanmait.recycle.pojo.Photolib;
import com.wanmait.recycle.service.DataService;

@Controller
@RequestMapping("/manager")
public class RubbishDataController {

	@Resource
	private DataService dataService;
	
	@RequestMapping("rubbish/rubbishData")
	public ModelAndView rubbishData(String beginTime,String endTime,String searchStr,Integer enable) {
		if(enable==null) {
			enable=1;
		}
		ModelAndView mv = new ModelAndView();
		PageInfo<Data> pageInfo = null;
		Map<String,String> criteriaMap = new HashMap<>();
		
		if(beginTime!=""||endTime!=""||searchStr!="") {
			pageInfo = dataService.findAllByCriteria(enable,beginTime, endTime, searchStr);
			criteriaMap.put("beginTime", beginTime);
			criteriaMap.put("endTime", endTime);
			criteriaMap.put("searchStr", searchStr);

			
		}else {
			pageInfo = dataService.findAllData(enable);
		}
		mv.addObject("pageInfo", pageInfo);
		mv.addObject("criteriaMap", criteriaMap);
		mv.addObject("enable", enable);
		return  mv;
	}
	
	/*启用和禁用数据*/
	@RequestMapping("startAndStop")
	@ResponseBody
	public void startAndStop(Data data) {
		
		dataService.changeEnable(data);
	}
	
	
	
	
}
